package com.yikaiye.android.yikaiye.ui.activity.order;

import com.yikaiye.android.yikaiye.R;
import com.yikaiye.android.yikaiye.base.BaseActivity;
import com.yikaiye.android.yikaiye.base.BaseViewModel;
import com.yikaiye.android.yikaiye.config.Constant;
import com.yikaiye.android.yikaiye.databinding.ActivityOrderResultBinding;
import com.yikaiye.android.yikaiye.ui.activity.MainActivity;
import com.yikaiye.android.yikaiye.utils.JumpIntent;
import com.yikaiye.android.yikaiye.utils.UMengUtil;

/**
 * 订单支付结果
 */
public class OrderResultActivity extends BaseActivity<ActivityOrderResultBinding, BaseViewModel> {
    private boolean isPaySuccess = false;

    @Override
    protected BaseViewModel bindModel() {
        return getViewModel(this, BaseViewModel.class);
    }

    @Override
    protected void initInject() {
        getActivityComponent().inject(this);
    }

    @Override
    public void initData() {
        initTitleBar(getString(R.string.confirm_order));
        if (getIntent().getExtras() != null) {
            int resultStatus = getIntent().getExtras().getInt(Constant.RESULT_STATUS_KEY);
            // 1支付成功，-1支付失败
            if (resultStatus == 1) {
                isPaySuccess = true;
                binding.ivImage.setImageResource(R.mipmap.icon_pay_yes);
                binding.tvPayStatus.setText(getString(R.string.pay_success));
                binding.tvLookOrder.setText(getString(R.string.look_order));
                UMengUtil.setCountEventId(Constant.PAGE_PAY_SUCCESS);
            } else {
                isPaySuccess = false;
                binding.ivImage.setImageResource(R.mipmap.icon_pay_no);
                binding.tvPayStatus.setText(getString(R.string.pay_fail));
                binding.tvLookOrder.setText(getString(R.string.pay_again));
                UMengUtil.setCountEventId(Constant.PAGE_PAY_FAIL);
            }
        }
    }

    @Override
    protected void initClick() {
        viewModel.onDelayClick(binding.tvLookOrder, o -> {
            Constant.isFromPay = true;
            if (isPaySuccess) {
                Constant.currentPosition = 2;
                UMengUtil.setCountEventId(Constant.PAGE_LOOK_ORDER);
            } else {
                Constant.currentPosition = 1;
                UMengUtil.setCountEventId(Constant.PAGE_PAY_AGAIN);
            }
            JumpIntent.jump(OrderResultActivity.this, MainActivity.class, true);
        });
    }
}